/*
 * (C) 2014-2015 Alibaba Group Holding Limited
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *
 *     __  ___   ______        ___       __          ___
 *    |  |/  /  /  __  \      /   \     |  |        /   \
 *    |  '  /  |  |  |  |    /  ^  \    |  |       /  ^  \
 *    |    <   |  |  |  |   /  /_\  \   |  |      /  /_\  \
 *    |  .  \  |  `--'  |  /  _____  \  |  `----./  _____  \
 *    |__|\__\  \______/  /__/     \__\ |_______/__/     \__\
 *
 *
 *
 */
//
// Created by KOALA TEAM on 12/19/14.
//

#import <Foundation/Foundation.h>

/* 
 * Short hand NSLocalizedString, doesn't need 2 parameters
 */
#define LocalizedString(s) NSLocalizedString(s,s)

/*
 * LocalizedString with an additionl parameter for formatting
 */
#define LocalizedStringWithFormat(s,...) [NSString stringWithFormat:NSLocalizedString(s,s),##__VA_ARGS__]

enum {
	NSTruncateStringPositionStart=0,
	NSTruncateStringPositionMiddle,
	NSTruncateStringPositionEnd
}; typedef int NSTruncateStringPosition;

@interface NSString (KLHelper)


//operations
#pragma mark -
#pragma mark operations

- (NSString *)trim;
- (BOOL)isNotBlank;
- (BOOL)isEmpty;


- (BOOL)containsString:(NSString*)string;
- (BOOL)containsString:(NSString*)string options:(NSStringCompareOptions)options;
- (BOOL)containsEngAlphabet;

- (NSString*)stringByTruncatingToLength:(int)length;
- (NSString*)stringByTruncatingToLength:(int)length direction:(NSTruncateStringPosition)truncateFrom;
- (NSString*)stringByTruncatingToLength:(int)length
                              direction:(NSTruncateStringPosition)truncateFrom
                     withEllipsisString:(NSString*)ellipsis;

- (NSString *)stripStrangeWords;


- (NSString *)substringFromIndex:(NSUInteger)from untilCharset:(NSCharacterSet *)charset endOffset:(NSUInteger *)endOffset;
- (NSArray *)words;
- (NSString *)getOutOfTheNumber;
- (NSString *)firstLetter;
- (NSString *)firstLetters;


//code
#pragma mark -
#pragma mark code

- (NSString *)md5;
- (NSString *)SHA1;

- (NSString *)urlDecode;
- (NSString *)urlEncode;
- (NSString *)urlByAppendingDict:(NSDictionary *)params encoding:(BOOL)encoding;

// 十六进制字符串转换为16进制内存数据。
- (NSData *)toHexData;
//16进制数据转变成16进制表示的字符串
+ (NSString *)stringFromData:(NSData *)data;


#pragma mark -
#pragma mark json

+ (NSString *)jsonStringWithDictionary:(NSDictionary *)dictionary;
+ (NSString *)jsonStringWithArray:(NSArray *)array;
+ (NSString *)jsonStringWithString:(NSString *) string;
+ (NSString *)jsonStringWithObject:(id) object;

#pragma mark -
#pragma mark other

/*
 * Returns a comma separated NSString for an NSUInteger
 */
+ (NSString*)stringWithFormattedUnsignedInteger:(NSUInteger)integer;


- (long)longValue;
- (long long)longLongValue;
- (unsigned long long)unsignedLongLongValue;

// 统计字符数
- (int)lengthOfBytesUsingGB18030Encoding;

+(NSString *)stringFromResFile:(NSString *)name encoding:(NSStringEncoding)encode;
@end


@interface KLRONSStringUtil : NSObject

+ (BOOL)isBlank:(NSString *)str;
+ (BOOL)isNotBlank:(NSString *)str;
+ (NSString *)safeConvertString:(id)value;
@end
